package tj.eskhata.pos.examples;

import java.util.Iterator;

import org.apache.wicket.PageParameters;
import org.apache.wicket.ResourceReference;
import org.apache.wicket.markup.html.PackageResource;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.RefreshingView;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.spring.injection.annot.SpringBean;

import tj.eskhata.pos.*;
import tj.eskhata.pos.dao.BankDao;
import tj.eskhata.pos.domain.Bank;
import tj.eskhata.pos.domain.Client;
import tj.eskhata.pos.domain.Country;
import tj.eskhata.pos.domain.Status;
import tj.eskhata.pos.domain.User;
import tj.eskhata.pos.services.PosService;
import tj.eskhata.pos.web.BasePage;
import tj.eskhata.pos.web.model.DomainModelIteratorAdaptor;


public class Page2 extends BasePage {
	@SpringBean
	private PosService service;
	
	public Page2() {
		Bank bank= service.getBankDao().load(763);
		
		add(new Label("label2", "This is in the subclass Page2 "+service.findAllClients().subList(0, 15).size()));
		
		
		 add(new RefreshingView("users") {
	            @Override
	            protected Iterator getItemModels() {
	              return new DomainModelIteratorAdaptor<User>(service
	                  .findAllUsers().subList(0,5).iterator()) {
	                @Override
	                protected IModel model(Object object) {
	                  return new CompoundPropertyModel((User) object);
	                }
	              };
	            }

	            @Override
	            protected void populateItem(Item item) {
	              item.add(new Label("wiaUsername"));
	              item.add(new Label("id"));
	              item.add(new Label("fullname"));
	              item.add(new Label("status.code"));
	            }
	          });
		
		 add(new RefreshingView("countries") {
	            @Override
	            protected Iterator getItemModels() {
	              return new DomainModelIteratorAdaptor<Client>(service
	                  .findAllClients().subList(0,15).iterator()) {
	                @Override
	                protected IModel model(Object object) {
	                  return new CompoundPropertyModel((Client) object);
	                }
	              };
	            }

	            @Override
	            protected void populateItem(Item item) {
	              item.add(new Label("name"));
	              //item.add(new Label("code"));
	              //item.add(new Label("fullName"));              
	            }
	          });

	}
}
